package org.linlinjava.litemall.wx.web;

import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.service.WxDistributionBenefitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/wx/distributionBenefit")
public class WxDistributionBenefitController {
    @Autowired
    private WxDistributionBenefitService distributionBenefitService;

    /**
     * 获取分销收益记录
     * @param userId
     * @return
     */
    @GetMapping("/list")
    public Object list(@LoginUser Integer userId,
                       @RequestParam(required = false,defaultValue = "1") Integer page,
                       @RequestParam(required = false,defaultValue = "10")Integer size,
                       @RequestParam(required = false,defaultValue = "add_time") String sort,
                       @RequestParam(required = false,defaultValue = "desc") String order) {
        if (userId == null) {
            return ResponseUtil.unlogin();
        }
        return ResponseUtil.okList(distributionBenefitService.list(userId, page, size, sort, order));
    }

    /**
     * 获取用户分销总计收益
     * @param userId
     * @return
     */
    @GetMapping("/myDistributionBenefit")
    public Object queryMyDistributionBenefit(@LoginUser Integer userId) {
        if (userId == null) {
            return ResponseUtil.unlogin();
        }
        return ResponseUtil.ok(distributionBenefitService.queryMyDistributionBenefit(userId));
    }

}
